//
//  SickManagerController.m
//  QuickCure1
//
//  Created by JianFeng on 16/11/4.
//  Copyright © 2016年 maoge. All rights reserved.
//
#import "UserManager.h"

#import "SickHeaderTableView.h"
#import "SickManagerController.h"
#import "SickWriteController.h"
@interface SickManagerController ()
@property (strong, nonatomic) IBOutlet UIButton *addButton;
//
@property(nonatomic,strong)UserManager *usermanager;
@property(nonatomic,weak)SickHeaderTableView *tabViews;
@property(nonatomic,strong)NSMutableArray *dictArray;

@end
@implementation SickManagerController

- (void)viewDidLoad {
    [super viewDidLoad];
    //沙盒取数据
    [self getDataFromShaHe];
    
    [self setupTabelView];
}
//沙盒取数据
-(void)getDataFromShaHe
{
    self.usermanager = [UserManager sharedManager];
    [_usermanager loadCasesFromCache];
    self.dictArray = self.usermanager.presonBingLIMDList;
}

//TabelView
-(void)setupTabelView
{
    self.navigationController.navigationBar.translucent = NO;
    SickHeaderTableView *tabViews = [[SickHeaderTableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
    [self.view addSubview:tabViews];
    _tabViews = tabViews;
    
    //去掉分隔线
    tabViews.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    if (self.dictArray.count > 0) {
        tabViews.modelArray = self.dictArray;
    }
    //
    [tabViews mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(self.view);
        make.bottom.equalTo(self.addButton.mas_top).offset(-5);
    }];
}
-(IBAction)addButtonCliock:(UIButton *)sender {
    SickWriteController *nextViewVC = [[SickWriteController alloc]init];
    //创建可变数组
    if (!self.dictArray){
        self.dictArray = [UserManager sharedManager].presonBingLIMDList;
    }
    //block的数据回调
    __weak SickManagerController *VC = self;
    nextViewVC.navBarIitmBlock = ^(PresonMondel *dict){
        [VC.dictArray insertObject:dict atIndex:0];
        //赋值
        VC.tabViews.modelArray = VC.dictArray;
        [VC.tabViews reloadData];
#pragma mark -----数据保存
        _usermanager = [UserManager sharedManager];
        _usermanager.presonBingLIMDList = self.dictArray;
        [_usermanager saveCasesToCache];
    };

    [self.navigationController pushViewController:nextViewVC animated:YES];
}
@end
